﻿using Common.Contract;
using Common.Contract.Customer;
using Common.Contract.Customer.Record;
using Common.Contract.Customer.Request;
using Common.Contract.Customer.Response;
using Common.Contract.Customer.Response.CustomerManager;
using Common.Contract.Paging;
using Common.Contract.SystemConfig.Record;
using Common.Data.Repository.Enum;
using Common.Service;
using Common.Service.DataTables;
using SMECustomerWebsite.Core.Configuration;
using SMECustomerWebsite.Filters;
using SMECustomerWebsite.Models.ViewModels.CustomerAlert;
using SMECustomerWebsite.Models.ViewModels.CustomerManager;
using SMECustomerWebsite.Models.ViewModels.ExportData.AlertCustomer;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web.Mvc;

namespace SMECustomerWebsite.Controllers
{
    public class CustomerAlertController : ControllerBase
    {

        #region View
        [CustomActionFilter]
        [Authorize]
        public ActionResult Index()
        {
            return View();
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult GeneralAlert()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        #endregion

        #region Alert
        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertBadbank()
        {
            AlertTopdownViewModel vm = new AlertTopdownViewModel
            {
                CurrentUser = CurrentUserRecord,
                BusinessDate = GetBusinessDateByTableName("TBL_ALERT_BAD_BANK_TOPDOWN").Value
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertBadbankWatchlist()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertBadBankBottomup()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult ListBadbank()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }
        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertOverdueDate()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }
        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertCardOverdue()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertLoanMaturity()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertCurrentAccount()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertDepositMaturity()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertLCMaturity()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertBLMaturity()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertLimitMaturity()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult AlertCustInactive()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult Celebration()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult Representative()
        {
            CustomerPortfolioViewModel vm = new CustomerPortfolioViewModel
            {
                CurrentUser = CurrentUserRecord
            };
            return View(vm);
        }
        #endregion
        #region Data Alert
        [Authorize]
        [HttpPost]
        public ActionResult ListBadBank(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.MovingInDate = pageRequest.SearchColumns[7];
                        break;
                    case "2":
                        filter.MovingInDate = pageRequest.SearchColumns[6];
                        break;
                    case "3":
                        filter.MovingInDate = pageRequest.SearchColumns[5];
                        break;
                    case "4":
                        filter.MovingInDate = pageRequest.SearchColumns[3];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.ListBadBank"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    Lang = CurrentLang,
                    CurrentUser = CurrentUserRecord,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerBadBankResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerBadBank(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertCustomerRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.MovingInDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.MovingInDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.MovingInDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.MovingInDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertOverdueData(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Acctno = pageRequest.SearchColumns[6];
                        filter.Balance = pageRequest.SearchColumns[7];
                        filter.NoOverdueDate = pageRequest.SearchColumns[8];
                        break;
                    case "2":
                        filter.Acctno = pageRequest.SearchColumns[5];
                        filter.Balance = pageRequest.SearchColumns[6];
                        filter.NoOverdueDate = pageRequest.SearchColumns[7];
                        break;
                    case "3":
                        filter.Acctno = pageRequest.SearchColumns[4];
                        filter.Balance = pageRequest.SearchColumns[5];
                        filter.NoOverdueDate = pageRequest.SearchColumns[6];
                        break;
                    case "4":
                        filter.Acctno = pageRequest.SearchColumns[3];
                        filter.Balance = pageRequest.SearchColumns[3];
                        filter.NoOverdueDate = pageRequest.SearchColumns[4];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.ListBadBank"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    Lang = CurrentLang,
                    CurrentUser = CurrentUserRecord,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerAlertOverdueResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertOverdue(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertOverdueRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CusName,
                                                             x.ContractNo,
                                                             x.SoDu,
                                                             x.NoOvdDays,
                                                             x.DuNoGoc,
                                                             x.LaiTrongKy,
                                                             x.LaiQuaHan,
                                                             x.LaiPhat
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.ContractNo,
                                                             x.SoDu,
                                                             x.NoOvdDays,
                                                             x.DuNoGoc,
                                                             x.LaiTrongKy,
                                                             x.LaiQuaHan,
                                                             x.LaiPhat
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.BranchNameSme,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.ContractNo,
                                                             x.SoDu,
                                                             x.NoOvdDays,
                                                             x.DuNoGoc,
                                                             x.LaiTrongKy,
                                                             x.LaiQuaHan,
                                                             x.LaiPhat
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Region,
                                                             x.BranchNameSme,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.ContractNo,
                                                             x.SoDu,
                                                             x.NoOvdDays,
                                                             x.DuNoGoc,
                                                             x.LaiTrongKy,
                                                             x.LaiQuaHan,
                                                             x.LaiPhat
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }
        [Authorize]
        [HttpPost]
        public ActionResult AlertCardOverdueData(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Acctno = pageRequest.SearchColumns[6];
                        filter.OvdLevel = pageRequest.SearchColumns[7];
                        filter.NoOverdueDate = pageRequest.SearchColumns[8];
                        filter.DateOvd = pageRequest.SearchColumns[9];
                        filter.MinPay = pageRequest.SearchColumns[10];
                        filter.Balance = pageRequest.SearchColumns[11];
                        filter.DateBaddebt = pageRequest.SearchColumns[12];
                        break;
                    case "2":
                        filter.Acctno = pageRequest.SearchColumns[5];
                        filter.OvdLevel = pageRequest.SearchColumns[6];
                        filter.NoOverdueDate = pageRequest.SearchColumns[7];
                        filter.DateOvd = pageRequest.SearchColumns[8];
                        filter.MinPay = pageRequest.SearchColumns[9];
                        filter.Balance = pageRequest.SearchColumns[10];
                        filter.DateBaddebt = pageRequest.SearchColumns[11];
                        break;
                    case "3":
                        filter.Acctno = pageRequest.SearchColumns[4];
                        filter.OvdLevel = pageRequest.SearchColumns[5];
                        filter.NoOverdueDate = pageRequest.SearchColumns[6];
                        filter.DateOvd = pageRequest.SearchColumns[7];
                        filter.MinPay = pageRequest.SearchColumns[8];
                        filter.Balance = pageRequest.SearchColumns[9];
                        filter.DateBaddebt = pageRequest.SearchColumns[10];
                        break;
                    case "4":
                        filter.Acctno = pageRequest.SearchColumns[2];
                        filter.OvdLevel = pageRequest.SearchColumns[3];
                        filter.NoOverdueDate = pageRequest.SearchColumns[4];
                        filter.DateOvd = pageRequest.SearchColumns[5];
                        filter.MinPay = pageRequest.SearchColumns[6];
                        filter.Balance = pageRequest.SearchColumns[7];
                        filter.DateBaddebt = pageRequest.SearchColumns[8];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.ListBadBank"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    Lang = CurrentLang,
                    CurrentUser = CurrentUserRecord,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerAlertCardOverdueResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertCardOverdue(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertCardOverdueRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.ContractCif,
                                                             x.CusName,
                                                             x.ContractNumber,
                                                             x.OvdLevel,
                                                             x.OvdDays,
                                                             x.OvdDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.MinPayment.ToString("##,##0.00"),
                                                             x.TotalBalance.ToString("##,##0.00"),
                                                             x.BaddebtDate.HasValue? x.BaddebtDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture):string.Empty,
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.ContractCif,
                                                             x.CusName,
                                                             x.ContractNumber,
                                                             x.OvdLevel,
                                                             x.OvdDays,
                                                             x.OvdDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.MinPayment.ToString("##,##0.00"),
                                                             x.TotalBalance.ToString("##,##0.00"),
                                                             x.BaddebtDate.HasValue? x.BaddebtDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture):string.Empty,
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.BranchNameSme,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.ContractCif,
                                                             x.CusName,
                                                             x.ContractNumber,
                                                             x.OvdLevel,
                                                             x.OvdDays,
                                                             x.OvdDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.MinPayment.ToString("##,##0.00"),
                                                             x.TotalBalance.ToString("##,##0.00"),
                                                             x.BaddebtDate.HasValue? x.BaddebtDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture):string.Empty,
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Region,
                                                             x.BranchNameSme,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.ContractCif,
                                                             x.CusName,
                                                             x.ContractNumber,
                                                             x.OvdLevel,
                                                             x.OvdDays,
                                                             x.OvdDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.MinPayment.ToString("##,##0.00"),
                                                             x.TotalBalance.ToString("##,##0.00"),
                                                             x.BaddebtDate.HasValue? x.BaddebtDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture):string.Empty,
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }
        [Authorize]
        [HttpPost]
        public ActionResult AlertBadBank(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Color1 = pageRequest.SearchColumns[7];
                        filter.Color2 = pageRequest.SearchColumns[8];
                        filter.Color3 = pageRequest.SearchColumns[9];
                        break;
                    case "2":
                        filter.Color1 = pageRequest.SearchColumns[6];
                        filter.Color2 = pageRequest.SearchColumns[7];
                        filter.Color3 = pageRequest.SearchColumns[8];
                        break;
                    case "3":
                        filter.Color1 = pageRequest.SearchColumns[5];
                        filter.Color2 = pageRequest.SearchColumns[6];
                        filter.Color3 = pageRequest.SearchColumns[7];
                        break;
                    case "4":
                        filter.Color1 = pageRequest.SearchColumns[3];
                        filter.Color2 = pageRequest.SearchColumns[4];
                        filter.Color3 = pageRequest.SearchColumns[5];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertBadBank"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter,
                    Type = 1
                };
                var customerRecords = new RetrieveCustomerAlertBadbankResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertBadBank(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertCustomerRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.Month2,
                                                             x.Month1,
                                                             x.Month
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.Month2,
                                                             x.Month1,
                                                             x.Month
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.Month2,
                                                             x.Month1,
                                                             x.Month
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.Month2,
                                                             x.Month1,
                                                             x.Month
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertBadBankBottomup(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.CusStatus = pageRequest.SearchColumns[7];
                        break;
                    case "2":
                        filter.CusStatus = pageRequest.SearchColumns[6];
                        break;
                    case "3":
                        filter.CusStatus = pageRequest.SearchColumns[5];
                        break;
                    case "4":
                        filter.CusStatus = pageRequest.SearchColumns[3];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertBadBank"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter,
                    Type = 3
                };
                var customerRecords = new RetrieveCustomerAlertBadbankResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertBadBank(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertCustomerRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.Color
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.Color
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.Color
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.Color
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertBadBankWatchlist(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertBadBank"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter,
                    Type = 2
                };
                var customerRecords = new RetrieveCustomerAlertBadbankResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertBadBank(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertCustomerRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertLoanMatdt(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                filter.Industry = null;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Acctno = pageRequest.SearchColumns[6];
                        filter.Matdt = pageRequest.SearchColumns[7];
                        filter.Balance = pageRequest.SearchColumns[8];
                        break;
                    case "2":
                        filter.Acctno = pageRequest.SearchColumns[5];
                        filter.Matdt = pageRequest.SearchColumns[6];
                        filter.Balance = pageRequest.SearchColumns[7];
                        break;
                    case "3":
                        filter.Acctno = pageRequest.SearchColumns[4];
                        filter.Matdt = pageRequest.SearchColumns[5];
                        filter.Balance = pageRequest.SearchColumns[6];
                        break;
                    case "4":
                        filter.Acctno = pageRequest.SearchColumns[2];
                        filter.Matdt = pageRequest.SearchColumns[3];
                        filter.Balance = pageRequest.SearchColumns[4];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertLoanMatdt"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerLoanMatdtResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerLoanMatdt(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertCustomerRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustName,
                                                             x.Acctno,
                                                             x.Matdt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BalQd,
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.Acctno,
                                                             x.Matdt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BalQd,
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.Acctno,
                                                             x.Matdt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BalQd,
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.Acctno,
                                                             x.Matdt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BalQd,
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }
            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertGeneralData(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                filter.Industry = null;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Acctno = pageRequest.SearchColumns[6];
                        filter.Matdt = pageRequest.SearchColumns[7];
                        filter.Balance = pageRequest.SearchColumns[8];
                        break;
                    case "2":
                        filter.Acctno = pageRequest.SearchColumns[5];
                        filter.Matdt = pageRequest.SearchColumns[6];
                        filter.Balance = pageRequest.SearchColumns[7];
                        break;
                    case "3":
                        filter.Acctno = pageRequest.SearchColumns[4];
                        filter.Matdt = pageRequest.SearchColumns[5];
                        filter.Balance = pageRequest.SearchColumns[6];
                        break;
                    case "4":
                        filter.Acctno = pageRequest.SearchColumns[2];
                        filter.Matdt = pageRequest.SearchColumns[3];
                        filter.Balance = pageRequest.SearchColumns[4];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertLoanMatdt"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerAlertGeneralResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertGeneral(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertGeneralRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustomerName,
                                                             string.IsNullOrEmpty(x.LoanMat)?string.Empty:x.LoanMat,
                                                             string.IsNullOrEmpty(x.DepositMat)?string.Empty:x.DepositMat,
                                                             string.IsNullOrEmpty(x.BlMat)?string.Empty:x.BlMat,
                                                             string.IsNullOrEmpty(x.LimitMat)?string.Empty:x.LimitMat,
                                                             string.IsNullOrEmpty(x.LoanOverdue)?string.Empty:x.LoanOverdue,
                                                             string.IsNullOrEmpty(x.CardOverdue)?string.Empty:x.CardOverdue,
                                                             string.IsNullOrEmpty(x.CasaDesc)?string.Empty:x.CasaDesc,
                                                             string.IsNullOrEmpty(x.DormantWarn)?string.Empty:x.DormantWarn
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustomerName,
                                                             string.IsNullOrEmpty(x.LoanMat)?string.Empty:x.LoanMat,
                                                             string.IsNullOrEmpty(x.DepositMat)?string.Empty:x.DepositMat,
                                                             string.IsNullOrEmpty(x.BlMat)?string.Empty:x.BlMat,
                                                             string.IsNullOrEmpty(x.LimitMat)?string.Empty:x.LimitMat,
                                                             string.IsNullOrEmpty(x.LoanOverdue)?string.Empty:x.LoanOverdue,
                                                             string.IsNullOrEmpty(x.CardOverdue)?string.Empty:x.CardOverdue,
                                                             string.IsNullOrEmpty(x.CasaDesc)?string.Empty:x.CasaDesc,
                                                             string.IsNullOrEmpty(x.DormantWarn)?string.Empty:x.DormantWarn
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.BranchName,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustomerName,
                                                             string.IsNullOrEmpty(x.LoanMat)?string.Empty:x.LoanMat,
                                                             string.IsNullOrEmpty(x.DepositMat)?string.Empty:x.DepositMat,
                                                             string.IsNullOrEmpty(x.BlMat)?string.Empty:x.BlMat,
                                                             string.IsNullOrEmpty(x.LimitMat)?string.Empty:x.LimitMat,
                                                             string.IsNullOrEmpty(x.LoanOverdue)?string.Empty:x.LoanOverdue,
                                                             string.IsNullOrEmpty(x.CardOverdue)?string.Empty:x.CardOverdue,
                                                             string.IsNullOrEmpty(x.CasaDesc)?string.Empty:x.CasaDesc,
                                                             string.IsNullOrEmpty(x.DormantWarn)?string.Empty:x.DormantWarn
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Region,
                                                             x.BranchName,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustomerName,
                                                             string.IsNullOrEmpty(x.LoanMat)?string.Empty:x.LoanMat,
                                                             string.IsNullOrEmpty(x.DepositMat)?string.Empty:x.DepositMat,
                                                             string.IsNullOrEmpty(x.BlMat)?string.Empty:x.BlMat,
                                                             string.IsNullOrEmpty(x.LimitMat)?string.Empty:x.LimitMat,
                                                             string.IsNullOrEmpty(x.LoanOverdue)?string.Empty:x.LoanOverdue,
                                                             string.IsNullOrEmpty(x.CardOverdue)?string.Empty:x.CardOverdue,
                                                             string.IsNullOrEmpty(x.CasaDesc)?string.Empty:x.CasaDesc,
                                                             string.IsNullOrEmpty(x.DormantWarn)?string.Empty:x.DormantWarn
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }
            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertCasa(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                filter.Industry = null;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Balance1 = pageRequest.SearchColumns[6];
                        filter.Balance2 = pageRequest.SearchColumns[7];
                        filter.Balance3 = pageRequest.SearchColumns[8];
                        filter.Balance4 = pageRequest.SearchColumns[9];
                        break;
                    case "2":
                        filter.Balance1 = pageRequest.SearchColumns[5];
                        filter.Balance2 = pageRequest.SearchColumns[6];
                        filter.Balance3 = pageRequest.SearchColumns[7];
                        filter.Balance4 = pageRequest.SearchColumns[8];
                        break;
                    case "3":
                        filter.Balance1 = pageRequest.SearchColumns[4];
                        filter.Balance2 = pageRequest.SearchColumns[5];
                        filter.Balance3 = pageRequest.SearchColumns[6];
                        filter.Balance4 = pageRequest.SearchColumns[7];
                        break;
                    case "4":
                        filter.Balance1 = pageRequest.SearchColumns[2];
                        filter.Balance2 = pageRequest.SearchColumns[3];
                        filter.Balance3 = pageRequest.SearchColumns[4];
                        filter.Balance4 = pageRequest.SearchColumns[5];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertCasa"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerAlertCasaResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertCasa(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertCustomerRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustName,
                                                             x.AvgbalQdN4,
                                                             x.AvgbalQdN3,
                                                             x.AvgbalQdN2,
                                                             x.AvgbalQdN1
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.AvgbalQdN4,
                                                             x.AvgbalQdN3,
                                                             x.AvgbalQdN2,
                                                             x.AvgbalQdN1
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.AvgbalQdN4,
                                                             x.AvgbalQdN3,
                                                             x.AvgbalQdN2,
                                                             x.AvgbalQdN1
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.AvgbalQdN4,
                                                             x.AvgbalQdN3,
                                                             x.AvgbalQdN2,
                                                             x.AvgbalQdN1
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }
            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertDepositMatdt(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                filter.Industry = null;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Acctno = pageRequest.SearchColumns[6];
                        filter.Term = pageRequest.SearchColumns[7];
                        filter.Matdt = pageRequest.SearchColumns[8];
                        filter.Balance = pageRequest.SearchColumns[9];
                        break;
                    case "2":
                        filter.Acctno = pageRequest.SearchColumns[5];
                        filter.Term = pageRequest.SearchColumns[6];
                        filter.Matdt = pageRequest.SearchColumns[7];
                        filter.Balance = pageRequest.SearchColumns[8];
                        break;
                    case "3":
                        filter.Acctno = pageRequest.SearchColumns[4];
                        filter.Term = pageRequest.SearchColumns[5];
                        filter.Matdt = pageRequest.SearchColumns[6];
                        filter.Balance = pageRequest.SearchColumns[7];
                        break;
                    case "4":
                        filter.Acctno = pageRequest.SearchColumns[2];
                        filter.Term = pageRequest.SearchColumns[3];
                        filter.Matdt = pageRequest.SearchColumns[4];
                        filter.Balance = pageRequest.SearchColumns[5];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertDepositMatdt"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveTblAlertDepositMatdtResponse();
                customerRecords = serviceClient.Proxy.RetrieveTblAlertDepositMatdt(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<TblAlertDepositMatdtRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustomerName,
                                                             x.Acctno,
                                                             x.Term,
                                                             x.Matdt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BalQd,
                                                             x.BranchCode
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustomerName,
                                                             x.Acctno,
                                                             x.Term,
                                                             x.Matdt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BalQd,
                                                             x.BranchCode
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustomerName,
                                                             x.Acctno,
                                                             x.Term,
                                                             x.Matdt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BalQd,
                                                             x.BranchCode
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Region,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustomerName,
                                                             x.Acctno,
                                                             x.Term,
                                                             x.Matdt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BalQd,
                                                             x.BranchCode
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertLCMatdt(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                filter.Industry = null;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Acctno = pageRequest.SearchColumns[6];
                        filter.Matdt = pageRequest.SearchColumns[8];
                        break;
                    case "2":
                        filter.Acctno = pageRequest.SearchColumns[5];
                        filter.Matdt = pageRequest.SearchColumns[7];
                        break;
                    case "3":
                        filter.Acctno = pageRequest.SearchColumns[4];
                        filter.Matdt = pageRequest.SearchColumns[6];
                        break;
                    case "4":
                        filter.Acctno = pageRequest.SearchColumns[2];
                        filter.Matdt = pageRequest.SearchColumns[4];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertLCMatdt"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerAlertLcResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertLc(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertLcMaturityRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CusName,
                                                             x.TransId,
                                                             x.Productname,
                                                             x.ExpiryDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.DaoCif,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.TransId,
                                                             x.Productname,
                                                             x.ExpiryDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.BranchName,
                                                             x.DaoCif,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.TransId,
                                                             x.Productname,
                                                             x.ExpiryDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.BranchName,
                                                             x.DaoCif,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.TransId,
                                                             x.Productname,
                                                             x.ExpiryDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertBLMatdt(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                filter.Industry = null;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Acctno = pageRequest.SearchColumns[6];
                        filter.Matdt = pageRequest.SearchColumns[7];
                        break;
                    case "2":
                        filter.Acctno = pageRequest.SearchColumns[5];
                        filter.Matdt = pageRequest.SearchColumns[6];
                        break;
                    case "3":
                        filter.Acctno = pageRequest.SearchColumns[4];
                        filter.Matdt = pageRequest.SearchColumns[5];
                        break;
                    case "4":
                        filter.Acctno = pageRequest.SearchColumns[2];
                        filter.Matdt = pageRequest.SearchColumns[3];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertBLMatdt"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerAlertBLResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertBL(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertBlMaturityRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CusName,
                                                             x.MdId,
                                                             x.MaturityDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.DaoCif,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.MdId,
                                                             x.MaturityDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.BranchNameSme,
                                                             x.DaoCif,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.MdId,
                                                             x.MaturityDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Region,
                                                             x.BranchNameSme,
                                                             x.DaoCif,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.MdId,
                                                             x.MaturityDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertLimitMatdt(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                filter.Industry = null;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.Acctno = pageRequest.SearchColumns[6];
                        filter.Matdt = pageRequest.SearchColumns[7];
                        break;
                    case "2":
                        filter.Acctno = pageRequest.SearchColumns[5];
                        filter.Matdt = pageRequest.SearchColumns[6];
                        break;
                    case "3":
                        filter.Acctno = pageRequest.SearchColumns[4];
                        filter.Matdt = pageRequest.SearchColumns[5];
                        break;
                    case "4":
                        filter.Acctno = pageRequest.SearchColumns[2];
                        filter.Matdt = pageRequest.SearchColumns[3];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertLimitMatdt"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerAlertLimitResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertLimit(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertLimitMaturityRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CusName,
                                                             x.Id,
                                                             double.Parse(x.InternalAmountQd).ToString("##,##0.00"),
                                                             x.ExpiryDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.Id,
                                                             double.Parse(x.InternalAmountQd).ToString("##,##0.00"),
                                                             x.ExpiryDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.BranchNameSme,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.Id,
                                                             double.Parse(x.InternalAmountQd).ToString("##,##0.00"),
                                                             x.ExpiryDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Region,
                                                             x.BranchNameSme,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CusName,
                                                             x.Id,
                                                             double.Parse(x.InternalAmountQd).ToString("##,##0.00"),
                                                             x.ExpiryDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.BranchCodeSme
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult AlertCustInactiveData(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.CusOpenDate = pageRequest.SearchColumns[7];
                        break;
                    case "2":
                        filter.CusOpenDate = pageRequest.SearchColumns[6];
                        break;
                    case "3":
                        filter.CusOpenDate = pageRequest.SearchColumns[5];
                        break;
                    case "4":
                        filter.CusOpenDate = pageRequest.SearchColumns[3];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertCustInactiveData"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerAlertInactiveResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertInactive(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<AlertCustomerRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.CusOpenDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.CusOpenDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.CusOpenDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             CurrentLang.Equals("vi")? x.Industry: x.IndustryEn,
                                                             x.CusOpenDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult CelebrationOfCompanyData(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.CustBirthDate = pageRequest.SearchColumns[7];
                        break;
                    case "2":
                        filter.CustBirthDate = pageRequest.SearchColumns[6];
                        break;
                    case "3":
                        filter.CustBirthDate = pageRequest.SearchColumns[5];
                        break;
                    case "4":
                        filter.CustBirthDate = pageRequest.SearchColumns[3];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerCelebrationRequest request = new RetrieveCustomerCelebrationRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerManagerController.CelebrationOfCompanyData"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerCelebrationResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerCelebration(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<CustomerRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":

                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.CIF,
                                                             x.Name,
                                                             CurrentLang.Equals("vi")? x.VpbIndustry: x.VpbIndustryEn,
                                                             x.BirthIncorpDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Address
                        }).ToList()
                        };
                        break;
                    case "3":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.CIF,
                                                             x.Name,
                                                             CurrentLang.Equals("vi")? x.VpbIndustry: x.VpbIndustryEn,
                                                             x.BirthIncorpDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Address
                    }).ToList()
                        };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch.BranchName,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.CIF,
                                                             x.Name,
                                                             CurrentLang.Equals("vi")? x.VpbIndustry: x.VpbIndustryEn,
                                                             x.BirthIncorpDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Address
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch.Region,
                                                             x.Branch.BranchName,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.CIF,
                                                             x.Name,
                                                             CurrentLang.Equals("vi")? x.VpbIndustry: x.VpbIndustryEn,
                                                             x.BirthIncorpDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Address
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }
            }
            return Json(pageResponse);
        }

        [Authorize]
        [HttpPost]
        public ActionResult CelebrationOfRepresentativeData(DataTablesPageRequest pageRequest)
        {
            DataTableResponse pageResponse = null;
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                FilterRecord filter = GetBaseFilter(pageRequest.SearchColumns);
                filter.Industry = null;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "1":
                        filter.RelationName = pageRequest.SearchColumns[6];
                        filter.RelationPosition = pageRequest.SearchColumns[7];
                        filter.RelationBirthDate = pageRequest.SearchColumns[8];

                        break;
                    case "2":
                        filter.RelationName = pageRequest.SearchColumns[5];
                        filter.RelationPosition = pageRequest.SearchColumns[6];
                        filter.RelationBirthDate = pageRequest.SearchColumns[7];
                        break;
                    case "3":
                        filter.RelationName = pageRequest.SearchColumns[4];
                        filter.RelationPosition = pageRequest.SearchColumns[5];
                        filter.RelationBirthDate = pageRequest.SearchColumns[6];
                        break;
                    case "4":
                        filter.RelationName = pageRequest.SearchColumns[2];
                        filter.RelationPosition = pageRequest.SearchColumns[3];
                        filter.RelationBirthDate = pageRequest.SearchColumns[4];
                        break;
                    default:
                        break;
                }
                RetrieveCustomerRepresentativeCelebrationRequest request = new RetrieveCustomerRepresentativeCelebrationRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerManagerController.CelebrationOfRepresentativeData"
                    },
                    Page = new PageRecord
                    {
                        PageSize = pageRequest.DisplayLength,
                        PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Region = DataRegion.RegionMap(CurrentUserRecord.Zone),
                    Filter = filter
                };
                var customerRecords = new RetrieveCustomerRepresentativeCelebrationResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerRepresentativeCelebration(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<CustomerRepresentativeRecord>() : customerRecords.Records;
                switch (CurrentUserRecord.GroupIdentifier)
                {
                    case "4":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Cif,
                                                             x.CustName,
                                                             x.RepresentativeName,
                                                             x.Position,
                                                             x.CelebrationDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    case "3": pageResponse = new DataTableResponse
                    {
                        sEcho = pageRequest.Echo,
                        iTotalRecords = customerRecords.Page.TotalRecords,
                        sColumns = pageRequest.ColumnNames,
                        aaData = resultCustomer.Select(x => new object[]{
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.RepresentativeName,
                                                             x.Position,
                                                             x.CelebrationDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Cif
                    }).ToList()
                    };
                        break;
                    case "2":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.RepresentativeName,
                                                             x.Position,
                                                             x.CelebrationDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    case "1":
                        pageResponse = new DataTableResponse
                        {
                            sEcho = pageRequest.Echo,
                            iTotalRecords = customerRecords.Page.TotalRecords,
                            sColumns = pageRequest.ColumnNames,
                            aaData = resultCustomer.Select(x => new object[]{
                                                             x.Zone,
                                                             x.Branch,
                                                             x.Dao,
                                                             x.DaoName,
                                                             x.Cif,
                                                             x.CustName,
                                                             x.RepresentativeName,
                                                             x.Position,
                                                             x.CelebrationDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                                                             x.Cif
                    }).ToList()
                        };
                        break;
                    default:
                        break;
                }

            }
            return Json(pageResponse);
        }
        #endregion
        #region Export to Excel
        [CustomActionFilter]
        [Authorize]
        public ActionResult ExportDataCustomerOverdue()
        {
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerManagerController.ExportDataTotalCustomer"
                    },
                    Page = new PageRecord
                    {
                        //PageSize = pageRequest.DisplayLength,
                        //PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    Lang = CurrentLang,
                    CurrentUser = CurrentUserRecord,
                    Filter = new FilterRecord
                    {
                        Branch = CurrentUserRecord.BranchId,
                        DaoName = string.Join(",", GetListDaoManager().ToArray())
                    }
                };
                var customerRecords = new RetrieveCustomerAlertOverdueResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertOverdue(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<ExportCustOverdueViewModel>() : customerRecords.Records.Select(x => new ExportCustOverdueViewModel
                {
                    Dao = x.Dao,
                    StaffName = x.DaoName,
                    Cif = x.Cif,
                    CustName = x.CusName,
                    Industry = x.IndustryName,
                    AcctNo = x.ContractNo,
                    NoOverdueDays = x.NoOvdDays
                }).ToList();

                var fileName = "Total Customers SME Overdue " + CurrentUserRecord.Branch + ".xlsx";
                DataTable dt = new DataTable();
                dt.TableName = "List of customers overdue";
                dt = ToDataTable(resultCustomer);
                ExportToExcel(dt, fileName);
            }
            return RedirectToAction("AlertOverdueDate", "CustomerAlert");
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult ExportDataCustomerDormant()
        {
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                RetrieveCustomerAlertRequest request = new RetrieveCustomerAlertRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerAlertController.AlertCustInactiveData"
                    },
                    Page = new PageRecord
                    {
                        //PageSize = pageRequest.DisplayLength,
                        //PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = new FilterRecord
                    {
                        Branch = CurrentUserRecord.BranchId,
                        DaoName = string.Join(",", GetListDaoManager().ToArray())
                    }
                };
                var customerRecords = new RetrieveCustomerAlertInactiveResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerAlertInactive(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<ExportCustDormantViewModel>() : customerRecords.Records.Select(x => new ExportCustDormantViewModel
                {
                    Dao = x.Dao,
                    StaffName = x.DaoName,
                    Cif = x.Cif,
                    CustName = x.CustName,
                    Industry = x.Industry
                }).ToList();

                var fileName = "Customers possibly dormant of " + CurrentUserRecord.Branch + ".xlsx";
                DataTable dt = new DataTable();
                dt.TableName = "List of customers possibly dormant";
                dt = ToDataTable(resultCustomer);
                ExportToExcel(dt, fileName);
            }
            return RedirectToAction("AlertCustInactive", "CustomerAlert");
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult ExportDataCelebration()
        {
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                RetrieveCustomerCelebrationRequest request = new RetrieveCustomerCelebrationRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerManagerController.CelebrationOfCompanyData"
                    },
                    Page = new PageRecord
                    {
                        //PageSize = pageRequest.DisplayLength,
                        //PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Lang = CurrentLang,
                    Filter = new FilterRecord
                    {
                        Branch = CurrentUserRecord.BranchId,
                        DaoName = string.Join(",", GetListDaoManager().ToArray())
                    }
                };
                var customerRecords = new RetrieveCustomerCelebrationResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerCelebration(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<ExportCustCelebrationViewModel>() : customerRecords.Records.Select(x => new ExportCustCelebrationViewModel
                {
                    Dao = x.Dao,
                    StaffName = x.DaoName,
                    Cif = x.CIF,
                    CustName = x.Name,
                    Industry = x.VpbIndustry,
                    BirthIncorpDate = x.BirthIncorpDate.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                }).ToList();

                var fileName = "Total Customers SME Celebration " + CurrentUserRecord.Branch + ".xlsx";
                DataTable dt = new DataTable();
                dt.TableName = "List of customers Celebration";
                dt = ToDataTable(resultCustomer);
                ExportToExcel(dt, fileName);
            }
            return RedirectToAction("Celebration", "CustomerAlert");
        }

        [CustomActionFilter]
        [Authorize]
        public ActionResult ExportDataRepresentative()
        {
            using (ServiceClient<ICustomer> serviceClient = new ServiceClient<ICustomer>())
            {
                RetrieveCustomerRepresentativeCelebrationRequest request = new RetrieveCustomerRepresentativeCelebrationRequest
                {
                    Header = new RequestHeaderRecord
                    {
                        ApplicationKey = SystemConfiguration.ApplicationKey,
                        CallerName = "SMEsCustomer360Degree.Controllers.CustomerManagerController.CelebrationOfRepresentativeData"
                    },
                    Page = new PageRecord
                    {
                        //PageSize = pageRequest.DisplayLength,
                        //PageIndex = pageRequest.DisplayLength > 0 ? pageRequest.DisplayStart / pageRequest.DisplayLength : 0
                    },
                    CurrentUser = CurrentUserRecord,
                    Region = DataRegion.RegionMap(CurrentUserRecord.Zone),
                    Filter = new FilterRecord
                    {
                        Branch = CurrentUserRecord.BranchId,
                        DaoName = string.Join(",", GetListDaoManager().ToArray())
                    }
                };
                var customerRecords = new RetrieveCustomerRepresentativeCelebrationResponse();
                customerRecords = serviceClient.Proxy.RetrieveCustomerRepresentativeCelebration(request);
                var resultCustomer = (customerRecords == null || customerRecords.Records == null) ? new List<ExportCustCelebrationViewModel>() : customerRecords.Records.Select(x => new ExportCustCelebrationViewModel
                {
                    Dao = x.Dao,
                    StaffName = x.DaoName,
                    Cif = x.Cif,
                    CustName = x.CustName,
                    Industry = x.RepresentativeName,
                    BirthIncorpDate = x.CelebrationDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                }).ToList();

                var fileName = "Total Customers SME Celebration " + CurrentUserRecord.Branch + ".xlsx";
                DataTable dt = new DataTable();
                dt.TableName = "List of customers Celebration";
                dt = ToDataTable(resultCustomer);
                ExportToExcel(dt, fileName);
            }
            return RedirectToAction("Representative", "CustomerAlert");
        }

        #endregion

    }
}
